import 'package:bxultimate/data/store/auth_store.dart';
import 'package:bxultimate/domain/common/result.dart';
import 'package:bxultimate/domain/home/eps_category.dart';
import 'package:bxultimate/domain/home/home_data_dto.dart';
import 'package:bxultimate/domain/home/search_hint.dart';
import 'package:bxultimate/shared/util/util_http.dart';

class HomeRequest {
  // APP 首页接口
  static Future<HomeDataDto> appHome() async {
    var userId = '';
    if (AuthStore.to.profile.id != null) {
      userId = AuthStore.to.profile.id.toString();
    }

    var response = await UtilHttp().get(
      '/app/andriod/appHome?sysUserId=' + userId,
    );
    return HomeDataDto.fromJson(response['data']);
  }

  // 文章详情
  static Future<Article> getArticleDetial(id) async {
    var response = await UtilHttp().get(
      '/app/andriod/appArticle/getArticleDetial?id=' + id,
    );
    return Article.fromJson(response['data']);
  }

  // 获取支前故事
  static Future<List<Article>> getZqgsArtical(page, size) async {
    var response = await UtilHttp().get(
      '/app/andriod/appArticle/getZqgsArtical?pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<Article>((item) => Article.fromJson(item))
        .toList();
  }

  // 获取文章列表
  static Future<List<Article>> getArticleList(page, size,categoryId) async {
    var response = await UtilHttp().get(
      '/app/andriod/appArticle/getArticleList?pageNumber=${page}&pageSize=${size}&categoryId=' + categoryId,
    );
    return response['data']['records']
        .map<Article>((item) => Article.fromJson(item))
        .toList();
  }

  // 获取我的任务
  static Future<List<Task>> getTaskList(page, size, status) async {
    var response = await UtilHttp().get(
      '/app/andriod/appTask/getTaskList?pageNumber=${page}&pageSize=${size}&status=' +
          status,
    );
    return response['data']['records']
        .map<Task>((item) => Task.fromJson(item))
        .toList();
  }

  // 获取任务详情
  static Future<Task> getTaskDetail(id) async {
    var response = await UtilHttp().get(
      '/app/andriod/appTask/getTaskDetail?id=' +
          id,
    );
    return Task.fromJson(response['data']);
  }

  // 更新任务状态
  static Future<Result> updateTaskStatus(data) async {
    var response = await UtilHttp().post(
      '/app/andriod/appTask/updateTaskStatus',
      data: data
    );
    return Result.fromJson(response);
  }



  // 文章分类tab
  static Future<List<EpsCategory>> getEpsCategory() async {
    var response = await UtilHttp().get(
      '/app/andriod/appArticle/getEpsCategory'
    );
    return response['data']
        .map<EpsCategory>((item) => EpsCategory.fromJson(item))
        .toList();
  }


  // 获取工作动态列表
  static Future<List<Job>> getJobReportList(page, size) async {
    var response = await UtilHttp().get(
      '/app/andriod/appJob/getJobReportList?pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<Job>((item) => Job.fromJson(item))
        .toList();
  }

  // 获取工作动态列表
  static Future<List<ShopActivity>> getShopActivity(page, size) async {
    var response = await UtilHttp().get(
      '/app/andriod/appHome/getShopActivity?pageNumber=${page}&pageSize=${size}',
    );
    return response['data']['records']
        .map<ShopActivity>((item) => ShopActivity.fromJson(item))
        .toList();
  }

  // 搜索列表
  static Future<List<Article>> getSearchList(page, size,keyWord,type) async {
    var response = await UtilHttp().get(
      '/app/andriod/appSearch/getSearchList?pageNumber=${page}&pageSize=${size}&type='+type+'&keyWord='+keyWord,
    );
    return response['data']['records']
        .map<Article>((item) => Article.fromJson(item))
        .toList();
  }
  // 搜索列表商家
  static Future<List<ShopActivity>> getSearchListShop(page, size,keyWord,type) async {
    var response = await UtilHttp().get(
      '/app/andriod/appSearch/getSearchList?pageNumber=${page}&pageSize=${size}&type='+type+'&keyWord='+keyWord,
    );
    return response['data']['records']
        .map<ShopActivity>((item) => ShopActivity.fromJson(item))
        .toList();
  }
  // 搜索提示
  static Future<List<SearchHint>> getSearchHintList(keyWord) async {
    var response = await UtilHttp().get(
      '/app/andriod/appSearch/getSearchHintList?keyWord='+ keyWord,
    );
    return response['data']
        .map<SearchHint>((item) => SearchHint.fromJson(item))
        .toList();
  }



}
